package com.joshua.spring.integration;

import com.joshua.spring.util.JacksonUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * com.joshua.spring.business.integration -- IntegrationAuthenticationContext
 * description: 定义集成认证上下文
 *
 * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
 * @date 2020/1/6 11:02
 */
@Slf4j
public class IntegrationAuthenticationContext {

    private static ThreadLocal<IntegrationAuthentication> HOLDER = new ThreadLocal<>();

    public static void set(IntegrationAuthentication authentication) {
        HOLDER.set(authentication);
        log.info("Set integration authentication success...{}", JacksonUtils.obj2json(get()));
    }

    public static IntegrationAuthentication get() {
        return HOLDER.get();
    }

    public static void clear() {
        HOLDER.remove();
    }
}
